let noticeModel = require('notice.js')
let createReceiptOperation = require('../operation/createReceiptOperation.js')

/**
 * 从数组对象中，抽取图片地址
 * param images 是一个数组对象
 * 
 * return array 返回图片地址数组
 */
function getImagesUrl(images) {
  let result = []
  for (let index = 0, length = images.length; index < length; index++) {
    result.push(images[index].url)
  }

  return result
}

function createReceipt(source,notice,studentSid) {
  let that = source 

  if (noticeModel.RECEIPT_REQUIREMENT[0].value == notice.receiptRequirement) {  // 签收方式为“无”直接签收
    createReceiptOperation.createReceipt(source, { 'studentSid': studentSid, 'noticeSid': notice.sid, 'content': '' })
      .then(res => {

      })
  } else if (noticeModel.RECEIPT_REQUIREMENT[1].value == notice.receiptRequirement) { // 文字签收模式
    wx.navigateTo({
      url: '../receiptNotice/receiptNotice?studentSid=' + studentSid,
    })
  }
  else if (noticeModel.RECEIPT_REQUIREMENT[2].value == notice.receiptRequirement) { // 图片模式
    wx.chooseImage({
      count: 9,
      sizeType: ['compressed'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        getApp().globalData.param.images = res.tempFilePaths
        wx.navigateTo({
          url: '../receiptNotice/receiptNotice?studentSid=' + studentSid,
        })
      }
    })
  } else if (noticeModel.RECEIPT_REQUIREMENT[3].value == notice.receiptRequirement) { // 视频模式
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      compressed: true,
      maxDuration: 60,
      success: function (res) {
        getApp().globalData.param.video = res.tempFilePath
        wx.navigateTo({
          url: '../receiptNotice/receiptNotice?studentSid=' + studentSid,
        })
      }
    })
  }
}

module.exports = {
  getImagesUrl: getImagesUrl,
  createReceipt: createReceipt
}